package util

import (
	"log"
	"net"
)

//获取IP地址
func GetHostIp() string{
	addrList, e := net.InterfaceAddrs()
	if e!=nil{
		log.Print("获取ip失败：",e)
		return ""
	}
	var ip string
	for _, address := range addrList {
		if ipNet,ok:= address.(*net.IPNet);ok&&!ipNet.IP.IsLoopback(){
			if ipNet.IP.To4()!=nil{
				ip=ipNet.IP.String()
				break
			}
		}
	}
	return  ip
}
